/**
 * Author: Dmitry Ustimov
 * Date: 6/1/13
 * Time: 10:08 PM
 */

package com.gmail.dmitryustimov.ms.java7.chain_of_responsibility.mod.mod_multy_type_visit.demo.handlers6_request1;

import com.gmail.dmitryustimov.ms.java7.patternslib.chain_of_responsibility.singleevent.Handler;

import java.math.BigDecimal;

public class CocreteHandler3<T extends Request> extends Handler<T> {

    private String name;
    protected int level;
    private RequestVisitor request1Action = this.new Request1Action();

    private BigDecimal sum = BigDecimal.valueOf(0);

    public CocreteHandler3(String name, int level) {
        this.level = level;
        this.name = name;
    }

    @Override
    public void doAction(Request request) {
        request.accept(request1Action);
    }

    @Override
    public Boolean canHandle(Request request) {
        return request.getRequestLevel() <= level;
    }

    private class Request1Action implements RequestVisitor {
        @Override
        public void visit(Request1 request) {
            sum.add(BigDecimal.valueOf(1));
        }
    }
}
